package com.example.demo.Service.impl;

import com.example.demo.Service.ICollectService;
import com.example.demo.entity.vo.CollectProductVo;
import com.example.demo.mapper.CollectMapper;
import com.example.demo.mapper.ProductDetailMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ICollectServiceImpl implements ICollectService{

    @Autowired
    private ProductDetailMapper productDetailMapper;

    @Autowired

    private CollectMapper collectMapper;
    @Override
    public int collect(Long productId, Long userId) {
        int rs ;

        if(productDetailMapper.count(userId,productId)==0){
            rs = collectMapper.create(productId,userId);
        }
        else{
            rs = collectMapper.delete(productId,userId);
        }

        return rs;


    }

    @Override
    public List<CollectProductVo> select(Long userId) {
        return collectMapper.select(userId);
    }
}
